package com.ymatou.iapi.productmanager.testcase;

import org.json.JSONObject;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.productmanager.parameter.ProductCatalogListBean;
import com.ymatou.iapi.productmanager.service.GetProductCatalogInfosCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.ProductManagerCallService;
import com.ymttest.business.service.SellerProductCallService;
import com.ymttest.business.service.productdata.impl.ProductFactory;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.compare.AssertHelper;

public class Ts_GetProductCatalogList {
	private static GetProductCatalogInfosCall getProductCatalogListCall = new GetProductCatalogInfosCall();
	private static Integer sellerId = Integer.valueOf(EnvSetup.getData("productsellerid"));
	private static String sellerName = EnvSetup.getData("productsellername");	
	
	
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取商品规格列表");
	}
	
	@Before
	public void caseUp() {
	}
	
	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getProductCatalogListCall.getOpurl());
	}
	
	@After
	public void caseDown() {
		Logger.end();
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetProductCatalogList_001() {
		Logger.start(true,"获取商品规格列表-多规格商品");
		try{
			String productId = ProductFactory.getOnlyProduct(sellerId, sellerName).getProductId();
			checkGetProductCatalogList(sellerId,productId);
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetProductCatalogList_002() {
		Logger.start(true,"获取商品规格列表-组合商品");
		try{
			
			String productId = SellerProductCallService.addNewProductAsPackage(sellerId, sellerName, null).getJSONObject("Data").getString("ProductID");
			checkGetProductCatalogList(sellerId,productId);
			
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetProductCatalogList_003() {
		Logger.start(true,"获取商品规格列-非该商品买手无法查询该商品");
		try{
			
			String productId = ProductFactory.getOnlyProduct(sellerId, sellerName).getProductId();
			JSONObject ret = getProductCatalogListCall.call(sellerId+1, productId);
			Logger.verifyEquals(true, ret.isNull("Data"), "非该商品买手查询，结果应为空");
			
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	
	
	
	
	public static void checkGetProductCatalogList(int sellerId, String productId) throws Exception{
		
		JSONObject ret = getProductCatalogListCall.call(sellerId, productId);
		
		ProductCatalogListBean actBean = ProductManagerCallService
										.getBeanFromJson(ret.getJSONObject("Data"), 
										ProductCatalogListBean.class);
		
		
		
		ProductCatalogListBean tgtBean = ProductManagerCallService.getProductCatalogListBean(productId);
		
		
		AssertHelper.assertResultEqual(tgtBean, actBean, "GetProductCatalogList");
		
		
		
	}
}
